<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
	<title></title>
</head>

<body>
	<script>
		function GetQueryString(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			if (r != null) return unescape(r[2]);
			return null;
		}
		let loc = window.location.href;
		var code = GetQueryString('code')
		var agentNo = GetQueryString('recommenderNo')
		let ulrLengtj = 'returnUrl='
		var returnUrl = loc.substring(loc.indexOf(ulrLengtj) + ulrLengtj.length)
		if (code) {
			$.ajax({
				url: "/api/wx/authorization?format=json",
				type: "post",
				dataType: "json",
				contentType: "application/json",
				data: JSON.stringify({ code: code, agentNo: agentNo }),
				success: function (res) {
					localStorage.setItem('token', res.data.info.token)
					if (returnUrl.indexOf('/login/register') != -1) {
						returnUrl = returnUrl.replace(/login\/register/, "main/home")
					}
					window.location.replace(returnUrl)
				},
				error: function (error) {
					console.log('error+++:', error)
				}
			})
		} else {
			window.location.replace(returnUrl)
		}		
	</script>
</body>

</html>